import fetch from "src/utils/fetch";
import API from "src/utils/api";
import notification from "src/utils/notification";


const Step = {
  state: {

    stepList:{
      list:[],
    },

  },
  mutations: {
    // step列表数据
    SetStepListData(state,data){
      state.stepList.list=data.stepInfoList ? data.stepInfoList : [];
    },
  },
  actions: {

    // step 新增-编辑-删除
    doStepName: ({ state, commit }, params) => {

      let url='';

      if(params.cb){
        var cb=params.cb;
        delete params.cb;
      }

      if(params.type == 'add' || params.type == 'edit'){
        url=API.batch.stepOperateInfo;
      }else if(params.type == 'del'){
        url=API.batch.stepDeletedInfo;
      }else{
        return;
      }

      fetch({
        commit: commit,
        url: url,
        type: "post",
        data: params.data,
        showRegionLoading: true,
        success: (data)=>{
          notification.success('操作成功!');
          cb && cb();
          this.a.actions.getStepList({state, commit },{});
        },
      });
    },

    getStepList: ({ state, commit }, params) => {

      fetch({
        commit: commit,
        url: API.batch.stepList,
        type: "post",
        data: params,
        showRegionLoading: true,
        success: (data)=>{
          commit("SetStepListData", data);
        },
      });
    },
  },
  getters: {

    stepList:(state, rootState)=>state.stepList,

  }
};

export default Step;
